package com.manage.project.biz.controller;

import java.util.List;

import com.manage.project.biz.service.IBizShebeiService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.manage.framework.aspectj.lang.annotation.Log;
import com.manage.framework.aspectj.lang.enums.BusinessType;
import com.manage.project.biz.domain.BizJidiansheshiguzhangxuncha;
import com.manage.project.biz.service.IBizJidiansheshiguzhangxunchaService;
import com.manage.framework.web.controller.BaseController;
import com.manage.framework.web.domain.AjaxResult;
import com.manage.common.utils.poi.ExcelUtil;
import com.manage.framework.web.page.TableDataInfo;

/**
 Controller
 *
 * @author liang
 *
 */
@RestController
@RequestMapping("/biz/jidiansheshiguzhangxuncha")
public class BizJidiansheshiguzhangxunchaController extends BaseController
{
    @Autowired
    private IBizJidiansheshiguzhangxunchaService bizJidiansheshiguzhangxunchaService;
    @Autowired
    private IBizShebeiService bizShebeiService;
    /**
     * 查询故障巡查列表
     */
//    @PreAuthorize("@ss.hasPermi('biz:jidiansheshiguzhangxuncha:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizJidiansheshiguzhangxuncha bizJidiansheshiguzhangxuncha)
    {
        startPage();
        List<BizJidiansheshiguzhangxuncha> list = bizJidiansheshiguzhangxunchaService.selectBizJidiansheshiguzhangxunchaList(bizJidiansheshiguzhangxuncha);
        return getDataTable(list);
    }

    /**
     * 导出故障巡查列表
     */
//    @PreAuthorize("@ss.hasPermi('biz:jidiansheshiguzhangxuncha:export')")
    @Log(title = "故障巡查", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BizJidiansheshiguzhangxuncha bizJidiansheshiguzhangxuncha)
    {
        List<BizJidiansheshiguzhangxuncha> list = bizJidiansheshiguzhangxunchaService.selectBizJidiansheshiguzhangxunchaList(bizJidiansheshiguzhangxuncha);
        ExcelUtil<BizJidiansheshiguzhangxuncha> util = new ExcelUtil<BizJidiansheshiguzhangxuncha>(BizJidiansheshiguzhangxuncha.class);
        return util.exportExcel(list, "故障巡查数据");
    }

    /**
     * 获取故障巡查详细信息
     */
//    @PreAuthorize("@ss.hasPermi('biz:jidiansheshiguzhangxuncha:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(bizJidiansheshiguzhangxunchaService.selectBizJidiansheshiguzhangxunchaById(id));
    }

    /**
     * 新增故障巡查
     */
//    @PreAuthorize("@ss.hasPermi('biz:jidiansheshiguzhangxuncha:add')")
    @Log(title = "故障巡查", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizJidiansheshiguzhangxuncha bizJidiansheshiguzhangxuncha)
    {
        String suidaoname=bizJidiansheshiguzhangxuncha.getField1();
        String shebeicode=bizJidiansheshiguzhangxuncha.getField15();
        if(bizShebeiService.gugetByNameAndId(suidaoname,shebeicode)==null){
            return AjaxResult.error("该设备与隧道不匹配"); }
        return toAjax(bizJidiansheshiguzhangxunchaService.insertBizJidiansheshiguzhangxuncha(bizJidiansheshiguzhangxuncha));
    }

    /**
     * 修改故障巡查
     */
    @Log(title = "故障巡查", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizJidiansheshiguzhangxuncha bizJidiansheshiguzhangxuncha)
    {
        String suidaoname=bizJidiansheshiguzhangxuncha.getField1();
        String shebeicode=bizJidiansheshiguzhangxuncha.getField15();
        if(bizShebeiService.gugetByNameAndId(suidaoname,shebeicode)==null){
            return AjaxResult.error("该设备与隧道不匹配"); }
        return toAjax(bizJidiansheshiguzhangxunchaService.updateBizJidiansheshiguzhangxuncha(bizJidiansheshiguzhangxuncha));
    }

    /**
     * 删除故障巡查
     */
//    @PreAuthorize("@ss.hasPermi('biz:jidiansheshiguzhangxuncha:remove')")
    @Log(title = "故障巡查", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bizJidiansheshiguzhangxunchaService.deleteBizJidiansheshiguzhangxunchaByIds(ids));
    }
}
